<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );


/**
 * @package		Joomla
 * @subpackage	JobBoard
 */
class JobBoardTableJA_Categories extends JTable
{
	/** @var int Primary key */
	var $id					= null;
	/** @var string */					
	var $name 				= null;
	/** @var string */
	var $parent_id 			= null;
	/** @var string */  
	var $params				= null;		
	/** @var string */  
	var $published		= null;
	var $ordering		= null;
	/** @var string */  
	var $checked_out		= null;
	/** @var string */  
	var $checked_out_time	= null;
	
	/**
	* @param database A database connector object
	*/
	function __construct(&$db)
	{
		parent::__construct( '#__ja_categories', 'id', $db );
	}
	
	/**
	 * Overloaded check function
	 *
	 * @access public
	 * @return boolean
	 * @see JTable::check
	 * @since 1.5
	 */
	function check()
	{
		JFilterOutput::objectHTMLSafe($this,ENT_QUOTES,'');
		//Check name
		if(empty($this->name))
			return JText::_('Name is empty');		
		//Check duplicate
					
		$where = '';
		if(!empty($this->id))
		{
			$where = ' and id != '.$this->id;
		}
		$query = "SELECT * FROM #__ja_categories WHERE upper(name) = upper('".$this->name."')".$where;
		
		//return $query;
		$db = &JFactory::getDBO();
		$db->setQuery($query);
				
		$result = $db->loadObjectList();
		
		if(count($result) >0)
			return JText::_("Categories name already exist");	
		
		return 'SUCCESS';
	}
	function load($key)
	{		
		parent::load($key);
		$this->name = JFilterInput::_decode($this->name);
		$this->name = JFilterInput::clean($this->name);
		return $this;
	}
}